const {getAdm,addAdm,updateAdm,deleteAdm,login} = require("../dao/admDao");
const bcryptjs = require('bcryptjs');
// 获取管理员
module.exports.getAdm = async function (user){
    return await getAdm(user)
};
//添加管理员
module.exports.addAdm = async function (user) {
    const data = await addAdm(user);
    if (data._id) {
        return true;
    }
    return false;
};
//修改管理员
module.exports.updateAdm = async function (user) {
    console.log(user);
    
    const data = await updateAdm(user);
    // console.log(data);
    
    if (data.ok) {
        return true;
    }
    return false;
}
//删除管理员
module.exports.deleteAdm = async function (row){
    return await deleteAdm(row)
};

// 登录


module.exports.login = async function (user){
    const data = await login({username:user.username})
    if(data.length>0){
        console.log(user.password,data[0].password)
        const isValid = bcryptjs.compareSync(user.password,data[0].password)
        console.log(data[0].password)
        if(isValid) {
            return isValid;
        }
    }
    return false
    
};